home *** CD-ROM | disk | FTP | other *** search
/ World of Education / World of Education.iso / world_s / startrek.zip / CHAPTER.009 < prev    next >
Text File  |  1989-05-15  |  22KB  |  463 lines

  1.         Chapter 9 PAGE 1 STARTREK THE COMPUTER PROGRAM
  2.  
  3.  
  4.                                     CHAPTER 9
  5.  
  6.         9.1 Shootback
  7.  
  8.              Now  that  the  Enterprise has  been  armed  with  offensive 
  9.         weapons  (Phasers  and Photon Torpedoes), and has  been  provided 
  10.         with  shields,  it is time to provide the enemy with a  means  to 
  11.         protect and defend themselves.  The Klingons are thus allowed  to 
  12.         take  hostile action against the Enterprise and are also  allowed 
  13.         to  move  around  inside the quadrant.   The  flowchart  for  the 
  14.         SHOOTBACK  subroutine which perform the hostile actions is  shown 
  15.         in figure 9.1 .  It is invoked by the main loop if there are  any 
  16.         Klingons  in  the  quadrant, or when the Enterprise  moves  in  a 
  17.         quadrant  containing Klingons.  The operation can take  place  in 
  18.         any  quadrant at any time, so the first thing to test is  if  the 
  19.         Enterprise  is docked at a Starbase.  If it is,  the  Starbases's 
  20.         shields  protect  the  Enterprise so there is  no  need  for  any 
  21.         further  action  in the subroutine.  A loop then takes  place  in 
  22.         which all eight elements in the Klingon Array are tested.  If any 
  23.         Klingon is active, namely it has a positive amount of energy, and 
  24.         the  "game over flag" is not set, signifying that the  Enterprise 
  25.         has been wiped out by previous Klingon action,  then it may  take 
  26.         hostile  action. If it does, it can either fire a photon  torpedo 
  27.         or use its phasers.
  28.  
  29.              If  it  fires off a torpedo, the torpedo can either  hit  or 
  30.         miss  the Enterprise.  if it hits the Enterprise, the  sub-system 
  31.         closest  to  the  point of impact is damaged,  if  it  misses,  a 
  32.         message to that effect is displayed.
  33.  
  34.              If  the  Klingon  has fired a phaser burst,  the  amount  of 
  35.         energy fired must be computed and deducted from the energy of the 
  36.         enemy  ship.  The amount of energy impacting the shields  of  the 
  37.         Enterprise must then be determined and subtracted from the amount 
  38.         of  energy  that  were  in the shields.   A  test  must  then  be 
  39.         performed  to  determine if the Enterprise's  shields  have  been 
  40.         beaten down to zero.  If they have, the game is over, the  player 
  41.         has  lost so the game over flag is set signifying that event  and 
  42.         the  loop is terminated because there is no point in letting  the 
  43.         remaining  Klingons in the quadrant fire at a non existent  ship.  
  44.         If  the Enterprise is still alive after the hit, the size of  the 
  45.         hit  must  be  examined  to  see if  it  was  massive  enough  to 
  46.         momentarily  overload  the  shields.  If such  an  overload  took 
  47.         place, then one of the ship's sub-systems closest to the point of 
  48.         impact is damaged.  
  49.  
  50.              Each  Klingon gets a turn to take hostile action and may  or 
  51.         may  not do so depending on how favorable a position it is on  at 
  52.         any  time.  Once all of them have had their chance, the  computer 
  53.         checks  to see if the energy in the shields of the Enterprise  is 
  54.         low, and if it is, displays a message warning the player of  that 
  55.         fact, before the subroutine terminates.
  56.  
  57.              A BASIC language version of the SHOOTBACK function is  shown 
  58.         in  figure  9.2.  It begins in line 600 with  the  usual  REMark.  
  59.  
  60.  
  61.         Copyright (c) Joe Kasser 1989
  62.  
  63.  
  64.  
  65.  
  66.  
  67.         Chapter 9 PAGE 2 STARTREK THE COMPUTER PROGRAM
  68.  
  69.  
  70.         Line 610 examines the state of the condition flag 'C$' to see  if 
  71.         the Enterprise is docked.  If it is, the program line counter  is 
  72.         advanced to line 680 bypassing the remainder of the subroutine.
  73.  
  74.              The loop begins at line 620 using the 'FOR/NEXT'  technique.  
  75.         The amount of energy available to the Klingon stored in the K3(I) 
  76.         array for each possible Klingon is tested.  If it is equal to  or 
  77.         less  than  zero,  the inside of the loop  is  bypassed  and  the 
  78.         program counter advanced on to line 670.  Also, there is a random 
  79.         probability that the Klingon, even if it is active will not fire. 
  80.         In that event,  the program counter is also advanced to line  670 
  81.         bypassing  the rest of the loop.  The function  'RND(Z)<.1*(I+Z)' 
  82.         is  used  to  determine the probability  of  the  Klingon  taking 
  83.         hostile  action.  A random number  is generated by the  computer.  
  84.         It  is  then  compared with a number  that  increases  for  every 
  85.         iteration  of the loop as follows.  The loop counter  (I)  ranges 
  86.         from  0  to  7.   Each  time around,  a  constant  value  of  one 
  87.         represented by the parameter 'Z' is added to the loop counter and 
  88.         the  result is multiplied by 0.1.  Each time the loop counter  is 
  89.         incremented,  the probability that the Klingon will take  hostile 
  90.         action is reduced.  For example, the limits are as follows
  91.  
  92.         I    PROBABILITY
  93.  
  94.         0    0.1
  95.         1    0.2
  96.         2    0.3
  97.         3    0.4
  98.         4    0.5
  99.         5    0.6
  100.         6    0.7
  101.         7    0.8
  102.  
  103.              thus the probability that the first Klingon will not fire is 
  104.         10%,  that the second in the quadrant will not fire is  20%  etc.  
  105.         This technique minimizes the probability that all the Klingons in 
  106.         the  quadrant  will  fire at the Enterprise so  that  the  player 
  107.         stands  some chance when going into a quadrant  containing  seven 
  108.         Klingons.  It is "realistic" to expect that not all Klingons will 
  109.         be in a position to fire at any one time.
  110.  
  111.              The  decision as to whether the Klingon fires a torpedo  or 
  112.         its phasers at the Enterprise is taken at the start of line  630.  
  113.         A  random  number is generated and compared with  the  amount  of 
  114.         energy  that  the  Klingon has, divided by  five  hundred.   This 
  115.         ensures  that as the energy level of the Klingon gets  lower  the 
  116.         probability  of  the  Klingon  Captain  deciding  to  use  photon 
  117.         torpedoes increases and the probability of the Klingon using  its 
  118.         phasers  decreases.   This is logical because phaser  bursts  are 
  119.         ineffectual  at  very low energy levels.   Two  "fallouts"  from 
  120.         using  the 'IF RND(Z)>K3(I)/500 ' statement are that the  Klingon 
  121.         will  never use its torpedoes when it has more than five  hundred 
  122.         units of energy, and, when you are trying to get it to  surrender 
  123.         by beating its shields down to zero slowly, it is liable to  keep 
  124.         firing torpedoes at you.  These torpedoes however home in on  the 
  125.  
  126.  
  127.         Copyright (c) Joe Kasser 1989
  128.  
  129.  
  130.  
  131.  
  132.  
  133.         Chapter 9 PAGE 3 STARTREK THE COMPUTER PROGRAM
  134.  
  135.  
  136.         energy  in  your shields, so that if you remember  to  keep  your 
  137.         shields at a minimum level, you should be able to dodge the enemy 
  138.         torpedoes.   If  a torpedo is fired, the program  flow  continues 
  139.         along line 630 and displays a message stating that a torpedo  has 
  140.         been  detected.  The program now has to determine if the  torpedo 
  141.         hit  and if so, if any damage was caused.  'H' is thus used as  a 
  142.         temporary  variable.   It is first set to a random percentage  of 
  143.         the  amount  of energy in the shields of the  Enterprise  by  the 
  144.         statement 'H=RND(Z)*E1'.   Since both the phaser and  torpedo  hit 
  145.         sections  of  the  subroutine  use  the  same  nested  subroutine 
  146.         starting  at  line 130 to process the hit and  determine  if  any 
  147.         damage occurred to the Enterprise, and this subroutine  subtracts 
  148.         the  amount of the hit from the energy levels of the  Enterprise, 
  149.         that  operation  in line 140 must be compensated  by  adding  the 
  150.         amount  of  the  hit  to the  energy  levels  before  the  nested 
  151.         subroutine  subtracts it so that the net result of the  hit  will 
  152.         not effect the energy levels aboard the ship.
  153.  
  154.              Line 630 then advances the program counter to line 660.  The 
  155.         phaser burst is processed in line 640.  A random percentage of up 
  156.         to forty percent of the energy aboard each Klingon is taken  from 
  157.         the Klingon by the statements 
  158.                       'H=K3(I)*.4*RND(Z) :  K3(I)=K3(I)-H' 
  159.         and  then  the  amount  of that energy  that  actually  hits  the 
  160.         Enterprise  is determined as a function of the  distance  between 
  161.         the Klingon and the Enterprise by the statement 'H=H/(SQR((K1(I)-
  162.         S1)^2+(K2(I)-S2)^2))^.4'   which  utilizes  basic   geometry   to 
  163.         determine the distance based on the row and column  co-ordinates 
  164.         (remember, the square of the sum of the sides of a right triangle 
  165.         is  equal  to .....).  Line 650 then displays the amount  of  the 
  166.         phaser  hit,  and both the phaser and torpedo hit  routines  come 
  167.         together  at line 660 which tells the player where the  offensive 
  168.         was launched from.  Line 660 displays the point of origin message 
  169.         even  if  the short range sensors are damaged, if you  wanted  to 
  170.         inhibit that you'd have to modify the line to read
  171.  
  172.         660 IF D(1)=0 THEN PRINT " from sector";K1(I)+Z;",";K2(I)+Z 
  173.         665 GOSUB 130 : IF F9>0 THEN 680
  174.  
  175.         and  introduce  a  new line (665).  Once  the  message  has  been 
  176.         displayed  the subroutine beginning at line 130 is called.   This 
  177.         subroutine processes the hit by subtracting the amount of the hit 
  178.         from  the shields of the Enterprise and determining if it  was  a 
  179.         massive  hit.   If  it was, then something  aboard  the  ship  is 
  180.         damaged.   After returning from the subroutine, the state of  the 
  181.         "end of game flag" (F9) is tested to determine if the  Enterprise 
  182.         was  destroyed by the enemy.  If it was, the program  counter  is 
  183.         advanced   forward  to  line  680  effectively  terminating   the 
  184.         subroutine.  This is an abnormal exit from the loop, but what  is 
  185.         the  point  of  staying in the loop if the  game  is  over.   The 
  186.         display generated by successive Klingons will be nonsense.
  187.  
  188.              The  loop  terminates at line 670 when all the  enemy  ships 
  189.         have had a turn to fire.  The last statement on the line,  checks 
  190.         the state of the shields.  If they contain less than one  hundred 
  191.  
  192.  
  193.         Copyright (c) Joe Kasser 1989
  194.  
  195.  
  196.  
  197.  
  198.  
  199.         Chapter 9 PAGE 4 STARTREK THE COMPUTER PROGRAM
  200.  
  201.  
  202.         units of energy , the computer will display a warning message  to 
  203.         the player.  The message contains the 'CHR$(7)' statement to also 
  204.         provide  an audible warning.  Line 680 terminate  the  subroutine 
  205.         with the usual 'RETURN' statement.
  206.  
  207.              The  flow  of  the SHOOTBACK subroutine  may  be  easier  to 
  208.         understand if it was written in the form shown in figure 9.3 in a 
  209.         cross between "flowchart" and BASIC.
  210.  
  211.              The  second part of the Klingon's defense capability is  the 
  212.         ability to move around.  Many versions of the game do not feature 
  213.         movement by the Klingons.  The player thus plays against "sitting 
  214.         ducks"  which  makes  the  game very easy.   On  the  other  hand 
  215.         allowing  the Klingons to move in between  quadrants  complicates 
  216.         the programming because separate matrices or arrays would have to 
  217.         be  used to store both the actual contents of a quadrant  at  any 
  218.         time,  and the value the computer placed in it at the  time  that 
  219.         the quadrant was scanned.  If a Klingon moves out of one quadrant 
  220.         into another, the arrays will then contain different values.  You 
  221.         may  be  interested  in  modifying the game  later  to  add  that 
  222.         capability, letting the enemy slowly move towards the  Enterprise 
  223.         or  towards the Starbases, or just move them at random, for  they 
  224.         too  can travel at warp speed.  That would  certainly  complicate 
  225.         the game, because then the map records would not be of any use in 
  226.         remembering  where the Klingons are, but only serve  to  remember 
  227.         where the bases are and which quadrants contain large numbers  of 
  228.         stars.  
  229.  
  230.              There are a number of algorithms that can be used for moving 
  231.         Klingons around the quadrant. for example, they can be positioned 
  232.         at  random.  They can be moved plus or minus a number of  sectors 
  233.         from  their  previous position.  They can be  moved  towards  the 
  234.         Enterprise  so  that they seem to be slowly "coming  in  for  the 
  235.         kill".
  236.  
  237.              Each  algorithm  requires a different  implementation.   The 
  238.         simplest  one to use is that shown in figure 9.4 which moves  the 
  239.         Klingons  about at random.  It can be argued that since they  are 
  240.         traveling at high speed, maneuvering both to attack and to  avoid 
  241.         the weapons fired by the Enterprise, their movement could  appear 
  242.         to be random.
  243.  
  244.              The flowchart is basically one big loop.  The state of  each 
  245.         possible enemy ship in the quadrant is tested.  If it is found to 
  246.         be  alive, a random sector is chosen.  If that sector  is  blank, 
  247.         the  Klingon  is  moved into it.  If the sector  is  occupied  by 
  248.         anything, the Klingon stays where it is.  An alternative approach 
  249.         could  be  to try again for a blank sector, but why  bother.  The 
  250.         sector it is occupying could just as easily show up as the chosen 
  251.         random  sector.   This approach does have one side  effect.   The 
  252.         more  things  that  there are in the quadrant,  the  greater  the 
  253.         probability  that the sector selected at random will be  occupied 
  254.         and  thus the greater the probability that the Klingon  will  not 
  255.         move.   Each approach used in implementing most functions of  the 
  256.         game  may  also  show up side effects that  were  not  specified.  
  257.  
  258.  
  259.         Copyright (c) Joe Kasser 1989
  260.  
  261.  
  262.  
  263.  
  264.  
  265.         Chapter 9 PAGE 5 STARTREK THE COMPUTER PROGRAM
  266.  
  267.  
  268.         Sometimes  these side effects work in your favor, sometimes  they 
  269.         don't  matter  and sometimes an alternative approach  has  to  be 
  270.         chosen  because the side effects are detrimental to the  program.  
  271.         In  our  case, there can only be up to seven stars, up  to  seven 
  272.         Klingons,  one  starbase  and the Enterprise  in  any  particular 
  273.         quadrant.  That  means  that out of sixty  four  sectors  in  the 
  274.         quadrant, only sixteen can be occupied in the worst case.  Nobody 
  275.         should  ever notice that there is a bias towards not  moving  the 
  276.         Klingons as a function of the number of objects in a sector.
  277.  
  278.              The BASIC language  version of the flowchart could take  the 
  279.         form shown in figure 9.5 which starts at line 700 with the  usual 
  280.         REMark.   The  loop begins at line 710. The loop used  takes  the 
  281.         form of a FOR/NEXT statement.
  282.  
  283.              K3(I)  is the flag that contains the state of  the  Klingon.  
  284.         If the value stored in the element of the array associated with a 
  285.         particular  Klingon is positive, the Klingon is alive  and  well.  
  286.         The test is performed using the statement 'IF K3(I)<=0 THEN 740'. 
  287.         which  causes the remainder of the subroutine to be  bypassed  if 
  288.         the  contents of the element are equal to or are less than  zero.  
  289.         In other words, if the Klingon is not active.
  290.  
  291.              Line  720 calls the subroutine in line 50 to find a pair  of 
  292.         random numbers between 0 and 7.  The last part of the line  tests 
  293.         a sector defined by those co-ordinates to see if it is blank.  If 
  294.         it is not blank, the program counter is advanced forward to  line 
  295.         740 bypassing the remainder of the subroutine.
  296.  
  297.                Line  730 moves the Klingon.  The contents of  the  sector 
  298.         matrix  represented  by  S(I,J)  are  set  to  one,   effectively 
  299.         emptying  the  sector  by the  statement  'S(K1(I),K2(I))  =  Z'.  
  300.         Remember,  K1(I) and K2(I) represent the position of the  Klingon 
  301.         in  the  quadrant.   The new position is set up by  the  pair  of 
  302.         statements  'K1(I) = X : K2(I) = Y' and lastly, the  contents  of 
  303.         the sector array associated with the Klingon are set to show  the 
  304.         presence of the Klingon by the statement 'S(X,Y) = 4'.  The  loop 
  305.         terminates  in line 740 as does the subroutine once the  loop  is 
  306.         over.
  307.  
  308.              In  this version of the game, the Klingons are moved  before 
  309.         they shoot back at the Enterprise.  The MOVEKLINGON subroutine is 
  310.         called  before the SHOOTBACK subroutine allowing the  Klingon  to 
  311.         shoot  after  it moved., The hit routine which displays  the  co-
  312.         ordinates  occupied  by  the  enemy ship when  It  fired  on  the 
  313.         Enterprise is then up to date when is your turn to shoot.  If the 
  314.         Klingons  shot  first and then moved, you would not  be  able  to 
  315.         locate them by the 'hit' message but would have to request a full 
  316.         short range sensor display each time you wanted to fire.
  317.  
  318.         9.3  Resign
  319.  
  320.              Now that the Klingons can fight back, you ought to be  given 
  321.         the  option of resigning from the game.  This way, when  you  are 
  322.         playing it in its current configuration you can give up and start 
  323.  
  324.  
  325.         Copyright (c) Joe Kasser 1989
  326.  
  327.  
  328.  
  329.  
  330.  
  331.         Chapter 9 PAGE 6 STARTREK THE COMPUTER PROGRAM
  332.  
  333.  
  334.         again if you get too badly damaged.  
  335.  
  336.              A flowchart of a typical resign sequence is shown in  figure 
  337.         9.6.  The flowchart begins by testing to see if any Klingons  are 
  338.         present  in  the  quadrant.  An attempt to  resign  in  a  battle 
  339.         situation  is  teated  as an attempt to  surrender  by  the  game 
  340.         simulator.  Since Klingons do not take prisoners, your  surrender 
  341.         is  not  accepted  and  they  continue  to  try  to  destroy  the 
  342.         Enterprise.
  343.  
  344.              If the simulator allows the player to resign, a verification 
  345.         must  be performed to make sure that the player realy intends  to 
  346.         resign  and  did not call the function by mistake.   It  is  good 
  347.         practice to always verify any critical operation in any  program.  
  348.         In  this case, what could be more critical than ending the  game.  
  349.         If the player really did intend to resign, the 'end of game' flag 
  350.         is set accordingly, if not the flowchart terminates.
  351.  
  352.         9.4  Transporter and Shuttlecraft
  353.  
  354.              The Transporter and the Shuttle allow you to possible obtain 
  355.         energy  and spare parts/materials without docking at a  starbase.   
  356.         You  can  use the computer to scan the quadrant you  are  in  and 
  357.         possibly  locate sources of energy and materials or parts.    You 
  358.         cannot however stock up on parts to expedite future repairs,  you 
  359.         can  only  obtain parts to repair anything damaged at  the  time.  
  360.         The Enterprise is a starship not a freighter.   Should you mine a 
  361.         lot  of energy, and have an excess when you dock at  a  starbase, 
  362.         the base will relieve you of the excess and send you on your  way 
  363.         with the standard amount.
  364.  
  365.              The Transporter allows you to beam a landing party down to a 
  366.         star system.  The Shuttlecraft allows you to send a landing party 
  367.         to  the  sustem.  The transporter uses energy,  the  shuttlecraft 
  368.         uses   time.    Once  the  landing  party  have   reached   their 
  369.         destination,  Mr Spok will notify you how much time  the  landing 
  370.         party have to spend on the ground to achieve their aims.
  371.  
  372.              The function of the landing party depends on where they are.  
  373.         If  they  have been landed near a source of  Dilithium  crystals, 
  374.         they  will  mine  the cystals and then  purify  them  using  some 
  375.         equipment  that Mr Scott will lash together.   Mr Spok will  give 
  376.         you  an estimate of the amount of energy that you can  expect  to 
  377.         receive  from the cystals that can be mined in a day.   You  then 
  378.         decide  how long the mining operation lasts, they stay there  for 
  379.         that amount of time and then return.
  380.  
  381.              If  the landing party is on an inhabited planet,  they  will 
  382.         make  a quick estimate of the amount of parts and materials  that 
  383.         they  can  find  so that the repairs to  the  Enterprise  can  be 
  384.         expedited.  You will again be asked to decide how much  time  the 
  385.         landing  party is to spend on the ground.  They will  stay  there 
  386.         for that amount of time, and then return.
  387.  
  388.              The Transporter cannot be operated, or the Shuttle  launched 
  389.  
  390.  
  391.         Copyright (c) Joe Kasser 1989
  392.  
  393.  
  394.  
  395.  
  396.  
  397.         Chapter 9 PAGE 7 STARTREK THE COMPUTER PROGRAM
  398.  
  399.  
  400.         if the shields are up.   On board sub-system repair goes on while 
  401.         the  landing party are doing their thing.  The flowchart for  the 
  402.         transporter is shown in figure 9.8.
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.         Copyright (c) Joe Kasser 1989
  458.  
  459.  
  460.  
  461.  
  462.  
  463.